how to load file from resources in c#

112

how to load file from resources in c# -

// required
using System.IO;
using System.Reflection;

public string GetEmbeddedResource(string namespacename, string filename)
{
    var assembly = Assembly.GetExecutingAssembly();
    var resourceName = namespacename + "." + filename;

    using (Stream stream = assembly.GetManifestResourceStream(resourceName))
    using (StreamReader reader = new StreamReader(stream))
    {
        string result = reader.ReadToEnd();
        return result;
    }
}

how to load file from resources in c# -

string s = GetEmbeddedResource("SociometryTree", "Notes.txt");

Comments

Submit
0 Comments